var fmtState = (s)=>s==1?"启用":"禁用";
function optFmt(value,row,index){
    var del="<a class='btn btn-danger del'><i class='glyphicon glyphicon-remove'></i> 删除</a>";
    var update="<a class='btn btn-success update'><i class='glyphicon glyphicon-remove'></i> 修改</a>";
    return del+"&emsp;"+update;
}
var optEvents= {
    "click .del": function (event, value, row, index) {

    },
    "click .update": function (event, value, row) {

    }
}

function search(){
   $("#userTb").bootstrapTable("refresh",{query:seria("#condition")});
}

function  queryParams(params) {
    var s=seria("#condition");
    Object.assign(params,s);
    return params;
}


$(function () {
    initGrant();
});
function  initGrant(){
    
    $("#grant").dialog({
        title:"用户授权",
        btnBind:function(){
            var rows01 = $("#userTb").bootstrapTable("getSelections");
            var rows02=$("#roleTb").bootstrapTable("getSelections");
            var params="userId="+rows01[0].id+"&roleId="+rows02[0].id;
            $.post("sys/user/grant",params).done(
                msg => {
                    $("#grant").dialog("close");
                    toastr.warning(eval(msg));
                    $("#userTb").bootstrapTable("refresh");
                }
            );
        }
    });
}
function grant() {
    var arr = $("#userTb").bootstrapTable("getSelections");
    if (arr.length != 1) {
        swal({
            type: "warning",
            title: "信息提示",
            text: "请选择一项且只能选择一项待授权！",
            showConfirmButton: true,
            showCancelButton: false
        });
        return;
    }
    $("#roleTb").bootstrapTable("checkBy", {field: "id", values: [arr[0].roleId]});
    $("#grant").dialog("open");
}

function batchDel() {
    //省略判断

    //$.swal();


    var rows = $("#userTb").bootstrapTable("getSelections");
    var params=rows.map(row => {
        return "ids="+row.id;
    }).join("&");
    $.ajax({
        url:"sys/user/batchDel",
        data:params,
        type:"POST"
        /*contentType:"application/json",*/
    }).done(msg=>{
        toastr.warning(msg);
        $("#userTb").bootstrapTable("refresh");
    });
}
